
import javax.swing.*;
/*TradeWithWhoDialog.java -- the player can choose the opponent to trade with.
 * structure -- 1 label(CENTER) & 4 buttons(3 players & cancel) on Jpanel(SOUTH) that is on JDialog(Borderlayout)
 */
import java.awt.*;
import java.awt.event.*;

public class TradeWithWhoDialog extends JDialog implements ActionListener{

	JPanel panelOnDialog;
	JButton cancel, opponent1, opponent2, opponent3;//player will choose opponent to trade with
	Player curPlayer, p1, p2, p3, p4;
	Player op1, op2, op3;
	TradeWithWhoDialog(){
		
		p1 = new Player();
		p2 = new Player();
		p3 = new Player();
		p4 = new Player();
		p1.setPlayerName("jason");
		p2.setPlayerName("randall");
		p3.setPlayerName("michael");
		p4.setPlayerName("takahiro");
		curPlayer = p3;
		
		//TEST PART
		p1.addNewProperty("Boardwalk");
		p1.addNewProperty("ReadingRailroad");
		p1.addNewProperty("PennsylvaniaRailroad");
		p1.addNewProperty("WaterWorks");
		p1.addNewProperty("ElectricCompany");
		
		p2.addNewProperty("MediterraneanAve");
		p2.addNewProperty("BalticAve");
		p2.addNewProperty("OrientalAve");
		p2.mortgage("OrientalAve");
		p2.buildHouse("MediterraneanAve", 1);
		
		
		p2.addNewProperty("StCharlesPlace");
		p2.addNewProperty("StatesAve");
		p2.addNewProperty("VirginiaAve");
		
		
		p2.addNewProperty("NewYorkAve");
		p2.addNewProperty("IllinoisAve");
		p2.addNewProperty("ParkPlace");
		//END OF TEST PART
		
		this.setLayout(new BorderLayout());
		this.setSize(250,150);
		
		this.add(new JLabel(" Who do you want to trade with?"), BorderLayout.CENTER);
		
		panelOnDialog = new JPanel();
		panelOnDialog.setLayout(new GridLayout(2,2, 8, 8));
		panelOnDialog.setBorder(BorderFactory.createEmptyBorder(8,8,8,8));
		this.add(panelOnDialog, BorderLayout.SOUTH);
		
		if(curPlayer == p1){
		opponent1 = new JButton(p2.getPlayerName());
		opponent2 = new JButton(p3.getPlayerName());
		opponent3 = new JButton(p4.getPlayerName());
		op1 = p2;
		op2 = p3;
		op3 = p4;
		}
		else if(curPlayer == p2){
			opponent1 = new JButton(p1.getPlayerName());
			opponent2 = new JButton(p3.getPlayerName());
			opponent3 = new JButton(p4.getPlayerName());
			op1 = p1;
			op2 = p3;
			op3 = p4;
		}
		else if(curPlayer == p3){
			opponent1 = new JButton(p1.getPlayerName());
			opponent2 = new JButton(p2.getPlayerName());
			opponent3 = new JButton(p4.getPlayerName());
			op1 = p1;
			op2 = p2;
			op3 = p4;
		}
		else if(curPlayer == p4){
			opponent1 = new JButton(p1.getPlayerName());
			opponent2 = new JButton(p2.getPlayerName());
			opponent3 = new JButton(p3.getPlayerName());
			op1 = p1;
			op2 = p2;
			op3 = p3;
		}
		cancel = new JButton("Cancel");
		panelOnDialog.add(opponent1);
		panelOnDialog.add(opponent2);
		panelOnDialog.add(opponent3);
		panelOnDialog.add(cancel);
		//make buttons listen to button press
		opponent1.addActionListener(this);
		opponent2.addActionListener(this);
		opponent3.addActionListener(this);
		cancel.addActionListener(this);
		
		this.setModal(true);
		this.setLocationRelativeTo(null);
		
		this.setVisible(true);
	}
	public void actionPerformed(ActionEvent e){
        if(e.getSource() == cancel){
            setVisible(false);
            //returnValue = 0;
        }
        if(e.getSource() == opponent1){
        	System.out.println("opp1 is pressed");
        	setVisible(false);
        	new TradeDialog(curPlayer, op1);
        }
        if(e.getSource() == opponent2){
        	System.out.println("opp2 is pressed");
        	setVisible(false);
        	new TradeDialog(curPlayer, op2);
        }
        if(e.getSource() == opponent3){
        	System.out.println("opp3 is pressed");
        	setVisible(false);
        	new TradeDialog(curPlayer, op3);
        }
        
        
    }
	
}